package com.htu.courseService.dictCode.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.htu.courseService.common.vo.R;
import com.htu.courseService.dictCode.entity.DictCode;
import com.htu.courseService.dictCode.service.DictCodeService;
import com.htu.courseService.user.entity.User;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dict")
@RequiredArgsConstructor
@Slf4j
public class DictCodeController {
    private final DictCodeService dictCodeService;

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param dictionaryCode
     * @return
     */
    @GetMapping("/page")
    public R<IPage<DictCode>> page(Integer pageNum,Integer pageSize,String dictionaryCode){
        IPage<DictCode> dictCodeIPage = dictCodeService.getPage(pageNum,pageSize,dictionaryCode);
        return R.success(dictCodeIPage);
    }

    @GetMapping("/list")
    public R<List<DictCode>> list(String dictionaryCode){
        List<DictCode> dictCodeList = dictCodeService.getList(dictionaryCode);
        return R.success(dictCodeList);
    }

    /**
     * 新增字典值
     * @param dictCode
     * @return
     */
    @PostMapping("/insert")
    public R<?> insert(@RequestBody DictCode dictCode){
        dictCodeService.insertDictCode(dictCode);
        return R.success("新增成功");
    }

    @DeleteMapping("/delete")
    public R<?> delete(Long id){
        dictCodeService.deleteDictCode(id);
        return R.success("删除成功");
    }

    @PutMapping("/update")
    public R<?> update(@RequestBody DictCode dictCode){
        dictCodeService.updateDictCode(dictCode);
        return R.success("修改成功");
    }
	
}
